package edu.ahut.ssm;

import util.Evaluator;
import util.GameHandler;
import util.parser.BinaryTree;

import java.util.ArrayList;
import java.util.List;

public class DFSApp2 {


    public static void main(String[] args) {
        int a = 1, b = 5, c = 5, d = 5;

        int cnt = 0;
        for (int x = 0; x < 4; x++)
            for (int y = 0; y < 4; y++)
                for (int z = 0; z < 4; z++) {
                    List<String> exp = new ArrayList<>();
                    exp.add(Integer.toString(a));
                    exp.add(Integer.toString(b));
                    exp.add(Integer.toString(c));
                    exp.add(Integer.toString(d));
                    exp.add(GameHandler.OPERATORS[x]);
                    exp.add(GameHandler.OPERATORS[y]);
                    exp.add(GameHandler.OPERATORS[z]);
                    //System.out.println(exp);
                    for (int i = 0; i < util.Util.FAC[7]; i++) {
                        int[] arr = util.Util.codel(i, 7);
                        List<String> exp2 = new ArrayList<>();
                        for (int j = 0; j < 7; j++) {
                            exp2.add(exp.get(arr[j]));
                        }
                        if (Evaluator.eval(exp2) == 24.0) {
                            BinaryTree tree = BinaryTree.createBinaryTree(exp2);
                            StringBuffer buffer = new StringBuffer();
                            tree.midVisit(buffer);//括号优化技术
                            System.out.println(buffer);
                            ++cnt;
                        }

                    }

                }

        System.out.println(cnt);

    }
}
